﻿
<?php
	include("php/session.php");
	include("php/error.php");
	include("php/bbcode.php");
	include("dao/ConteudoDAO.class.php");
	include("dao/CategoriasDAO.class.php");
	
	set_error_handler("customError");
	
	$idconteudo_get = $_GET['append'];
	$idcategoria_get = $_GET['appendcat'];
	$categoria_get = $_GET['match'];
	
	$conteudodao = new ConteudoDAO();
	$conteudo = $conteudodao->buscarConteudo($idconteudo_get);
	
	$categoriasdao = new CategoriasDAO();
	$categorias = $categoriasdao->buscar();
	
	$arrTags = array();
	$arrTags = $conteudodao->buscarTags($idconteudo_get);
	
	$str_conteudo = htmlspecialchars($conteudo->getConteudo());
	
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Chimera</title>
<link rel="stylesheet" type="text/css" href="css/css.css">
<link rel="stylesheet" type="text/css" href="css/prettify.css">
<link rel="stylesheet" type="text/css" href="css/modal.css">
<script src="js/run_prettify.js"></script>
<script src="js/jquery-1.11.1.js"></script>
<script src="js/campos.js"></script>
<script src="js/modal.js"></script>

<script>
	$(document).ready(function(e) {
        $("textarea").keydown(function(e) {
			if(e.keyCode === 9) { // tab was pressed
				// get caret position/selection
				var start = this.selectionStart;
					end = this.selectionEnd;
		
				var $this = $(this);
		
				// set textarea value to: text before caret + tab + text after caret
				$this.val($this.val().substring(0, start)
							+ "\t"
							+ $this.val().substring(end));
		
				// put caret at right position again
				this.selectionStart = this.selectionEnd = start + 1;
		
				// prevent the focus lose
				return false;
			}
		});
    });
</script>

</head>

<body>
	<main>
    
   	  <header>
          <div class="container">
              <div class="topoSuperior">
                  <a href="inicio.php"><span class="logo"></span></a>
                  <input type="text" class="pesquisaTopo" placeholder="Faça sua pesquisa..." />
                  <select class="categoriasPesquisa">
                      <?php foreach($categorias as $categoria): ?>
                          <option value="<?= $categoria->getIdCategorias();?>"><?= $categoria->getNome();?></option>
                      <?php endforeach;?>
                  </select>
                  <span class="logout">
                      <a href="php/logout.php"></a>
                  </span>
                  <span class="sessionNome"><?= $_SESSION['nome'] ?></span>
              </div>
              
              <div class="topoInferior">
            	<div class="menuTopo">
                	<span class="menuPost">Menu</span>
                    <span class="config">Opções</span>
                    <a href="#dialogNew" name="modal" class="new">Novo</span>
                    <a href="inicio.php" class="home">Início</a>
                    <a href="posts.php?append=<?= $idcategoria_get?>&match=<?= $categoria_get?>" class="menuPosts"><?= $categoria_get?></a>
                </div>
          </div>
      </header>
      
      <section class="novo">
        
        <div class="container">
            
            <div class="junteLeft">
            	
                <ul class="opcoes">
                    <li>
                    <a href="controller/remove.php?append=<?= $idconteudo_get?>&appendcat=<?=$conteudo->getFk_idCategorias()?>&match=<?= $categoria_get?>&action=1445" class="excluirPost">excluir</a>
                    </li>
                    <li><a href="#dialog" name="modal" class="editarPost">tags</a></li>

                </ul>
                
                <ul class="menu">
     
                    <?php foreach($categorias as $categoria): ?>
                    
                        <li>
                            <a href="posts.php?append=<?= $categoria->getIdCategorias();?>&match=<?= $categoria->getNome();?>">
                                <?= $categoria->getNome();?>
                            </a>
                        </li>
                    
                    <?php endforeach;?>
                
                </ul>
                
            </div>
            
            <div class="junteRight">
            	<h3 class="menuTitulo">Editar post em <?= $categoria_get?></h3>
            	<form class="formEditaNew"
                action="controller/edit.php?append=<?= $idconteudo_get?>&match=<?= $categoria_get?>&action=2445" method="post">
                	
                    <input type="text" class="inputAssuntoEdit" placeholder="Assunto" name="assunto" value="<?= $conteudo->getAssunto()?>"/>
                    <textarea id="mybox" class="inputConteudoEdit" placeholder="Escreva o texto aqui" name="conteudo"><?= $str_conteudo?></textarea>
                    
                    <a href="#" class="adicionarCampo">+</a>
                    
                    <div class="divTags">
                    	<input class="inputTags" name="tags[]" placeholder="Insira tags para pesquisa..."/>
                    </div>
                    
                    <input class="buttonEnviar" type="submit" value="Enviar" />
                    
                </form>
            </div>
            
      	</div>
        
      </section>
      
    </main>
    
    <div id="boxes">
            <div id="dialog" class="window shadow">
                <span class="close">X</span>
                <form action="controller/remove.php?action=1446&append=<?= $idconteudo_get?>&match=<?= $categoria_get?>" method="post">
                	<h3>tags</h3>
                	<ul>
                    <?php foreach($arrTags as $i => $tag){?>
                        <li><label><input type="checkbox" value="<?= $tag?>" name="tags[]"><?= $tag?></label></li>     	
                    <?php }?>
                    </ul>
                    <input type="submit" value="Excluir"/>
                </form>
            </div>

            <div id="mask"></div>
        </div>
    
</body>
</html>